package com.touch.workshop.ui.expgrowth;
import javax.swing.*;
import com.touch.graphingutil.*;
import com.touch.workshop.Database;
public class Curve extends JInternalFrame
{
	private static final long serialVersionUID = 6917753634981789980L;
	//the graph object
	protected JLineGraph graph = new JLineGraph("EXP Chart", CurveControls.CURVE_MINIMUM, CurveControls.CURVE_MAXIMUM);
	protected JScrollPane scroll = new JScrollPane();
	//menu system
	protected CurveMenuBar menubar = new CurveMenuBar();
	
	public Curve()
	{
		super("EXP Growth Curve", true, true, true, true);
		this.setJMenuBar(this.menubar);
		this.menubar.FILE.CLOSE.addActionListener(CurveHandlers.CURVE_MENU_HANDLER);
		this.menubar.FILE.NEW.addActionListener(CurveHandlers.CURVE_MENU_HANDLER);
		this.menubar.FILE.OPEN.addActionListener(CurveHandlers.CURVE_MENU_HANDLER);
		this.menubar.FILE.SAVE.addActionListener(CurveHandlers.CURVE_MENU_HANDLER);
		this.menubar.FILE.SAVEAS.addActionListener(CurveHandlers.CURVE_MENU_HANDLER);
		
		this.menubar.EDIT.VALUES.addActionListener(CurveHandlers.CURVE_MENU_HANDLER);
		this.menubar.EDIT.EXTREMES.addActionListener(CurveHandlers.CURVE_MENU_HANDLER);
		this.menubar.EDIT.EDIT.addActionListener(CurveHandlers.CURVE_MENU_HANDLER);
		
		this.menubar.VIEW.RESET.addActionListener(CurveHandlers.CURVE_MENU_HANDLER);		
		this.menubar.VIEW.SCALE.addActionListener(CurveHandlers.CURVE_MENU_HANDLER);		
		
		
		this.setSize(400, 300);		
		this.setContentPane(scroll);
		scroll.setViewportView(graph);
		this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
		
		this.update();
	}	
	public void update()
	{		
		this.changeScale(CurveControls.CURVE_MINIMUM, CurveControls.CURVE_MAXIMUM);
		for(Integer exp: Database.EXPCHART)
		{
			graph.addItem("", exp.intValue());		
		}
			
	}
	public void changeScale(int min, int max)
	{			
		this.graph = new JLineGraph("EXP Chart", min, max);
		scroll.setViewportView(graph);
		this.graph.addMouseMotionListener(CurveHandlers.CURVE_GRAPH_HANDLER);
		this.validate();
	}
	public void resetScale()
	{
		this.changeScale(0, Integer.MAX_VALUE);
	}	
}
